package com.swak.generate.codegen;

import com.swak.utils.StringUtils;

/**
 * 代码生成方案
 * 
 * @author lifeng
 * @date 2020年6月7日 下午4:30:33
 */
public class Scheme {

	private final String packageName;
	private final String moduleName;
	private final String className;
	private final Table table;
	private final boolean generateAll;
	private final boolean fluxDrive;
	private final boolean useMerge;

	public Scheme(String basePackage, Table table, boolean generateAll, boolean fluxDrive, boolean useMerge) {
		this.table = table;
		this.moduleName = this.parseModuleName();
		this.packageName = !StringUtils.endsWith(basePackage, this.moduleName) ? (basePackage + "." + this.moduleName)
				: basePackage;
		this.className = this.parseClassName();
		this.generateAll = generateAll;
		this.fluxDrive = fluxDrive;
		this.useMerge = useMerge;
	}

	private String parseClassName() {
		String className = table.getName();
		if (StringUtils.contains(table.getName(), "_")) {
			className = StringUtils.substringAfter(table.getName(), "_");
		}
		return StringUtils.convertColumn2Property(className);
	}

	private String parseModuleName() {
		String packageName = table.getName();
		if (StringUtils.contains(table.getName(), "_")) {
			packageName = StringUtils.substringBefore(table.getName(), "_");
		}
		return StringUtils.lowerCase(packageName);
	}

	public String getPackageName() {
		return packageName;
	}

	public String getModuleName() {
		return moduleName;
	}

	public String getClassName() {
		return className;
	}

	public Table getTable() {
		return table;
	}

	public boolean isGenerateAll() {
		return generateAll;
	}

	public boolean isFluxDrive() {
		return fluxDrive;
	}

	public boolean isUseMerge() {
		return useMerge;
	}
}
